package net.oschina.app.ui;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseActivity;
import net.oschina.app.bean.TweetBean;
import net.oschina.app.util.CommonUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import uk.co.senab.photoview.PhotoView;

/**
 * Created by wei03 on 2017/1/16.
 */

public class TweetActivity extends BaseActivity {

    @BindView(R.id.et_comment)
    EditText mEtComment;
    @BindView(R.id.iv_emoji)
    ImageView mIvEmoji;
    @BindView(R.id.iv_send)
    ImageView mIvSend;
    @BindView(R.id.gv_emoji)
    GridView mGvEmoji;
    @BindView(R.id.iv_icont)
    CircleImageView mIvIcont;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_time)
    TextView mTvTime;
    @BindView(R.id.tv_des1)
    TextView mTvDes1;
    @BindView(R.id.tv_praisecount1)
    TextView mTvPraisecount;
    @BindView(R.id.tv_commentcount1)
    TextView mTvCommentcount;
    @BindView(R.id.tv_des2)
    TextView mTvDes2;
    @BindView(R.id.ll_likelist)
    LinearLayout mLlLikelist;
    @BindView(R.id.iv_photo)
    PhotoView mIvPhoto;
    private TweetBean mBean;
    private String mTitle;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tweet_detail);
        ButterKnife.bind(this);
        getData();
        initView();
    }

    private void initView() {
        mActionBar.setTitle(mTitle);
        if (mBean != null) {
            Glide.with(CommonUtils.getContext()).load(mBean.getPortrait()).into(mIvIcont);
            mTvName.setText(mBean.getAuthor());
            mTvTime.setText(mBean.getPubDate());
            //富文本展示
            //CommonUtils.displayRichText(getApplicationContext(), mBean.getBody(), mTvDes1);
            mTvDes1.setText(Html.fromHtml(mBean.getBody()));
            if (mBean.getLikeCount() != 0) {
                mTvPraisecount.setText(String.valueOf(mBean.getLikeCount()));
            }
            if (mBean.getCommentCount() != 0) {
                mTvCommentcount.setText(String.valueOf(mBean.getCommentCount()));
            }
            if (mBean.getLikeList().size() != 0) {
                mLlLikelist.setVisibility(View.VISIBLE);
                List<TweetBean.UserBean> userBean = mBean.getLikeList();
                String username = "";
                for (int i = 0; i < userBean.size(); i++) {
                    if (i == 0) {
                        username = username + userBean.get(i).getName();
                    } else {
                        username = username + "," + userBean.get(i).getName();
                    }
                }
                mTvDes2.setText(username);
            }
            if (mBean.getImgSmall() != null) {
                mIvPhoto.setVisibility(View.VISIBLE);
                Glide.with(CommonUtils.getContext()).load(mBean.getImgSmall()).into(mIvPhoto);
            }else{
                mIvPhoto.setVisibility(View.GONE);
            }
        }
    }

    private void getData() {
        mBean = (TweetBean) getIntent().getSerializableExtra("bean");
        mTitle = getIntent().getStringExtra("title");
    }

    @OnClick({R.id.et_comment, R.id.iv_emoji, R.id.iv_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.et_comment:
                break;
            case R.id.iv_emoji:
                loadEmoji();
                break;
            case R.id.iv_send:
                break;
        }
    }

    private void loadEmoji() {
    }
}
